"use strict";
cc._RF.push(module, '2062d+pUmRJY5LUNzk1j5ez', 'bet_ssc_oneStar');
// scripts/bet/bet_ssc_oneStar.js

"use strict";

var _cc$Class;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
重庆时时彩 1星
*/
cc.Class((_cc$Class = {
    extends: cc.Component,

    properties: {
        fbSelBall: cc.Prefab, //选择球
        betContent: cc.Node, //投注选择面板
        ndMiss: cc.Node,
        sscPop: cc.Node, //根节点

        rules: [], //规则
        nums: [], //数值
        _curTopTitle: "一星直选", //当前玩法名
        _lotteryID: 0, //彩种id
        _curSelects: [], //选择球数字记录
        _isMiss: false, //是否开启遗漏
        _sscManage: null

        //_betManage:null,
    },

    //重置初始值
    initReset: function initReset() {
        //if(this._isMiss )
        //{
        //this._betManage.showMiss(this.betContent.children,this._lotteryID,this._lotteryID + this.rules.toString());
        //}
    },

    //外部传参
    init: function init(lotteryid) {
        this._lotteryID = lotteryid;
    },

    showMiss: function showMiss(data) {
        var childs = this.ndMiss.children;
        for (var i = 0; i < childs.length; i++) {
            if (i < data[0].length) {
                childs[i].getComponent(cc.Label).string = data[0][i];
            }
        }
        this.ndMiss.active = true;
    },

    hideMiss: function hideMiss() {
        this.ndMiss.active = false;
    },

    clearAllBetRecord: function clearAllBetRecord() {
        this.clearCurSel();
    },

    // use this for initialization
    start: function start() {
        this._sscManage = this.sscPop.getComponent(this.sscPop.name);
        if (this._sscManage == null) {
            ComponentsUtils.showTips("投注面板加载失败");
            return;
        }
        this._lotteryID = DEFINE.LOTTERY_ID.SSC_CQ;
        this.nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
        this.rules = DEFINE.LOTTERYRULESSC.ZHI_ONE;
        this.ndMiss.active = false;

        for (var j = 0; j < this.nums.length; j++) {
            var ball = cc.instantiate(this.fbSelBall);
            ball.getComponent(ball.name).init(j);
            WidgetExtUtils.addCheckEvent(ball, this.node, this.node.name, "onClickCallback", j);
            this.betContent.addChild(ball);
        }
        // this._betManage = cc.find("Canvas").getChildByName("ChatRoomPage").getChildByName("BetManage").getComponent("BetManage");
    },

    onClickCallback: function onClickCallback(toggle, customEventData) {
        if (toggle.getComponent(cc.Toggle).isChecked) {
            this._curSelects.push(customEventData);
        } else {
            Utils.removeByValue(this._curSelects, customEventData);
        }
        this.updateTgSelect();
        this.checkBet();
    },

    //检查倍数
    checkBet: function checkBet() {
        var bet = 0;
        bet = this._curSelects.length;
        this._sscManage.showAmount(bet);
    }

}, _defineProperty(_cc$Class, "clearAllBetRecord", function clearAllBetRecord() {
    this._curSelects.length = 0;
    for (var i = 0; i < this.betContent.children.length; i++) {
        this.betContent.children[i].getComponent(cc.Toggle).isChecked = false;
    }
}), _defineProperty(_cc$Class, "randomSelectCallBack", function randomSelectCallBack() {
    this.clearAllBetRecord();
    var randomArray = Utils.getRandomArrayWithArray(this.betContent.children, 1);
    if (randomArray.length > 0) {
        randomArray[0].getComponent(cc.Toggle).isChecked = true;
        var temp = randomArray[0].getComponent(cc.Toggle).checkEvents[0].customEventData;
        this.onClickCallback(randomArray[0], temp);
        return true;
    }
    return false;
}), _defineProperty(_cc$Class, "updateTgSelect", function updateTgSelect() {
    if (this._curSelects.length > 0) {
        window.Notification.emit("updateTgSelect", false);
    } else {
        window.Notification.emit("updateTgSelect", true);
    }
}), _defineProperty(_cc$Class, "dataObj", function dataObj() {
    //组合
    var obj = new Object();
    obj.PlayCode = parseInt(this._lotteryID + this.rules);
    var nums = "";
    Utils.sortNum(this._curSelects);
    for (var i = 0; i < this._curSelects.length; i++) {
        if (nums != "") nums += ",";
        nums += this._curSelects[i];
    }
    obj.num = nums;
    return obj;
}), _defineProperty(_cc$Class, "onMiss", function onMiss(toggle) {
    // if(toggle.getComponent(cc.Toggle).isChecked)
    // {
    //     this._isMiss = true;
    //     this._betManage.showMiss(this.betContent.children,this._lotteryID,this._lotteryID + this.rules.toString());
    // }    
    // else
    // {
    //     this._isMiss = false;
    //     this._betManage.setMiss(false,this.betContent.children,"");
    // }
}), _cc$Class));

cc._RF.pop();